package com.gzsxy.esjy.eureka.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRegisteredEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

/**
 * 服务注册监听器
 */
@Configuration
public class InstanceRegisterListener implements ApplicationListener<EurekaInstanceRegisteredEvent> {
    private static final Logger logger = LoggerFactory.getLogger(InstanceRegisterListener.class);

    @Override
    public void onApplicationEvent(EurekaInstanceRegisteredEvent event) {
        if (event != null && event.getInstanceInfo() != null){
            logger.info("服务：【{}】注册成功了，实例Id:【{}】",event.getInstanceInfo().getAppName(),event.getInstanceInfo().getInstanceId());
        } else {
            logger.error("服务：【未知】服务注册成功");
        }

    }
}
